<template>
	<view class="content">
		<view class="hint"><text>为维护大家的利益，请严格遵守《平台服务规范》</text></view>
		<view class="form">
			<view class="vc-item">
				<view>
					姓名
					<text class="tips-text" style="margin-left: 10rpx;">(必填)</text>
				</view>
				<view class="vc-item-content">
					<input
						type="text"
						class="vc-item-content-input"
						placeholder-class="vc-item-content-input-placeholder"
						v-model="registInfo.FullName"
						maxlength="50"
						placeholder="请输入姓名"
					/>
				</view>
			</view>
			<view class="vc-item" style="border-bottom: unset;">
				<view>
					身份证号
					<text class="tips-text" style="margin-left: 10rpx;">(必填)</text>
				</view>
				<view class="vc-item-content">
					<input
						type="idcard"
						class="vc-item-content-input"
						placeholder-class="vc-item-content-input-placeholder"
						v-model="registInfo.IdCardNo"
						maxlength="18"
						placeholder="请输入身份证号码"
					/>
				</view>
			</view>
		</view>
		<view class="uploadPic">
			<view class="title"><text>上传身份认证照片</text></view>
			<view class="uploadPicContainer">
				<view @click="uploadVerifyImg" v-if="registInfo.VerifyImg.length == 0" class="upload-auth-people-pic">
					<image :src="baseImageUrl + '/serveregist/add_people.png'" class="add-pic" />
				</view>
				<view v-else @click="uploadVerifyImg" class="people-auth-pic" :style="{ backgroundImage: 'url( ' + registInfo.VerifyImg + ' )' }"></view>
			</view>
			<view class="error-show"><view class="tips-text">手持身份证，注意反光，保证身份证内容清晰可见</view></view>
		</view>
		<view class="uploadIDCard">
			<view class="title"><text>上传身份证照片</text></view>
			<view class="idcard-front">
				<view
					class="idcard-front-pic"
					@click="uploadIdCardImg1"
					v-if="registInfo.IdCardImg1.length == 0"
					:style="{ backgroundImage: 'url( ' + baseImageUrl + '/serveregist/idcard_people.png)' }"
				>
					<image :src="baseImageUrl + '/serveregist/idcard_add.png'" class="add-pic" />
				</view>
				<image class="idcard-front-pic" @click="uploadIdCardImg1" v-else :src="registInfo.IdCardImg1"></image>
				<view
					class="idcard-front-pic"
					@click="uploadIdCardImg2"
					v-if="registInfo.IdCardImg2.length == 0"
					:style="{ backgroundImage: 'url( ' + baseImageUrl + '/serveregist/idcard_gh.png)' }"
				>
					<image :src="baseImageUrl + '/serveregist/idcard_add.png'" class="add-pic" />
				</view>
				<image class="idcard-front-pic" @click="uploadIdCardImg2" v-else :src="registInfo.IdCardImg2"></image>
			</view>

			<view class="error-show"><view class="tips-text">上传身份证的正反面照片，注意反光，保证身份证内容清晰可见</view></view>
		</view>
		<view class="submit-btn"><button @click="submit" class="bottom-change-view" :loading="submitUploadStatus" :disabled="submitUploadStatus">提交审核</button></view>
	</view>
</template>

<script>
import { baseImageUrl } from '@/config/config.js';
import { isLogin, toLogin, isBlankString, successToShow, errorToShow } from '@/config/common.js';
import { uploadImageToQiNiu } from '@/constant/home.js';
import { addServePlayerInfo } from '@/constant/schedule.js';
export default {
	data() {
		return {
			baseImageUrl: baseImageUrl,
			submitUploadStatus: false,
			registInfo: {
				VerifyImg: ''
			}
		};
	},
	onLoad(option) {
		if (isLogin()) {
			if (option.registInfo) {
				this.registInfo = JSON.parse(decodeURIComponent(option.registInfo));
				// this.registInfo.VerifyImg = 'http://qiniu.lvshuwangka.com/servepalyerregist/1b19c2ba-f802-4586-8459-ed5522ab3839.jpg';
				// this.registInfo.IdCardImg1 = 'http://qiniu.lvshuwangka.com/servepalyerregist/7d6ee6f5-522a-40ae-887f-4e7da5f36604.jpg';
				// this.registInfo.IdCardImg2 = 'http://qiniu.lvshuwangka.com/servepalyerregist/a521be86-5ddb-4a1c-ba95-d2c8d596c2b4.jpg';
			}
		} else {
			toLogin();
		}
	},
	methods: {
		uploadVerifyImg: function() {
			let that = this;
			uploadImageToQiNiu(1, 9, res => {
				this.registInfo.VerifyImg = res;
			});
		},
		uploadIdCardImg1: function() {
			let that = this;
			uploadImageToQiNiu(1, 9, res => {
				this.registInfo.IdCardImg1 = res;
			});
		},
		uploadIdCardImg2: function() {
			let that = this;
			uploadImageToQiNiu(1, 9, res => {
				this.registInfo.IdCardImg2 = res;
			});
		},
		async submit() {
			if (isBlankString(this.registInfo.FullName)) {
				errorToShow('请填写姓名');
				return false;
			}
			if (isBlankString(this.registInfo.IdCardNo)) {
				errorToShow('请填写身份证号');
				return false;
			}
			if (isBlankString(this.registInfo.VerifyImg)) {
				errorToShow('请上传身份认证照片');
				return false;
			}
			if (isBlankString(this.registInfo.IdCardImg1)) {
				errorToShow('请上传身份证正面照片');
				return false;
			}
			if (isBlankString(this.registInfo.IdCardImg2)) {
				errorToShow('请上传身份证背面照片');
				return false;
			}
			try {
				this.submitUploadStatus = true;
				await addServePlayerInfo(this.registInfo);
				successToShow('提交成功', res => {
					uni.reLaunch({
						url: '../../auditing/index'
					});
				});
			} catch {
				this.submitUploadStatus = false;
			}
		}
	}
};
</script>

<style lang="scss">
.hint {
	background: #fee7e7;
	color: #fc2424;
	font-size: $main-text-size-28;
	text-align: center;
	height: 60rpx;
	line-height: 60rpx;
	margin-bottom: 30rpx;
}

.tips-text {
	color: $main-text-color-grey;
	font-size: $main-text-size-20;
}

.vc-item {
	padding: 30rpx 30rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	border-bottom: 2rpx solid $main-line-color-gray-F5;
	font-family: 'SourceHanSansCN-Regular';
	font-size: $main-text-size-32;
	color: $main-text-color-gray-33;
	&-content {
		display: flex;
		align-items: center;
		justify-content: flex-end;
		max-width: 75%;
		.date-line {
			background-color: #333;
			width: 20rpx;
			height: 2rpx;
		}

		&-input {
			text-align: right;
		}
		.choose-tips-text {
			color: $main-text-color-grey;
		}
	}
	&-arrow {
		width: 18rpx;
		height: 32rpx;
		margin-left: 10rpx;
	}
}

/deep/ .vc-item-content-input-placeholder {
	color: $main-text-color-grey;
	font-size: $main-text-size-32;
}

.uploadPic {
	padding: 30rpx 30rpx;
	color: $main-text-color-gray-33;
	font-size: $main-text-size-32;

	.title {
		margin-bottom: 40rpx;
	}

	.uploadPicContainer {
		display: flex;
		justify-content: center;
		align-items: center;
		.upload-auth-people-pic {
			width: 360rpx;
			height: 360rpx;
			border: 2rpx solid #707070;
			display: flex;
			justify-content: center;
			align-items: center;
			border-radius: 20rpx;
			.add-pic {
				width: 194rpx;
				height: 194rpx;
			}
		}

		.people-auth-pic {
			width: 360rpx;
			height: 360rpx;
			border-radius: 20rpx;
			background-repeat: no-repeat;
			background-position: center;
			background-size: cover;
		}
	}
	.error-show {
		margin-top: 40rpx;
	}
}

.uploadIDCard {
	padding: 30rpx 30rpx;
	color: $main-text-color-gray-33;
	font-size: $main-text-size-32;
	.title {
		margin-bottom: 40rpx;
	}

	.idcard-front {
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		.idcard-front-pic {
			width: 660rpx;
			height: 444rpx;
			background-repeat: no-repeat;
			background-position: center;
			background-size: cover;
			display: flex;
			justify-content: center;
			align-items: center;
			margin-bottom: 40rpx;
			.add-pic {
				width: 194rpx;
				height: 194rpx;
			}
		}
	}
}

.submit-btn {
	margin-top: 60rpx;
	padding: 30rpx;
	button {
		width: 100%;
		color: #fff;
		font-size: $main-text-size-32;
	}
}
</style>
